package ycl.scheduled.controller.security;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import ycl.scheduled.common.ApiResult;
import ycl.scheduled.common.models.base.T;
import ycl.scheduled.common.models.req.base.ObjReq;
import ycl.scheduled.common.models.req.login.WechatLoginReq;
import ycl.scheduled.service.SecurityService;
import ycl.scheduled.service.SysUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: YCL
 * @date: 2022/01/20 10:39:50
 */
@RestController
@RequestMapping("/security")
@Api(tags = "权限")
public class SecurityController {

	@Resource
	private SecurityService securityService;
	@Resource
	private SysUserService userService;

	@GetMapping("/isLogin")
	@ApiOperation("查询用户是否登录")
	@ApiOperationSupport(order = 1)
	public ApiResult<T> isLogin(HttpServletRequest request){
		if (userService.isLogin(request))
			return ApiResult.success();
		return ApiResult.fail(null);
	}

	@PostMapping("/register")
	@ApiOperation("注册, 参数: {obj: [用户微信id]}")
	@ApiOperationSupport(order = 2)
	public ApiResult<T> register(ObjReq<String> req){
		securityService.register(req.getObj());
		return ApiResult.success();
	}


	@PostMapping("/login/wechatLogin")
	@ApiOperation("微信登录")
	@ApiOperationSupport(order = 11)
	public ApiResult<T> wechatLogin(@RequestBody WechatLoginReq req){
		securityService.wechatLogin(req);
		return ApiResult.success();
	}
}
